// page/projects/index.js
Page({
  data:{
    title: '积极的红色',
    array:['考试类型','中考','高考'],
    year:['考试年份',2017,2018,2019,2020,2021,2022,2023,2024,2025,2026],
    inx:0,
    index:0,
    status:true,
    tips:'',
    scrollTop:0,
    imgUrls:[
      '../../../image/static/page5_text1.png',
      '../../../image/static/page5_text2.png',
      '../../../image/static/page5_text3.png'
    ],
    indcatorDots:true,
    autoPlay:true,
    interval:5000,
    duration:500
  },
  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },
  bindPickerChangeYear:function(e){
    this.setData({
      inx: e.detail.value
    })
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  onShareAppMessage: function () {
    return {
      title: this.data.title,
      desc: app.globalData.userInfo.nickName+'分享给你'+this.data.title+'【海风教育】',
      path: 'page/projects/result/A/index?title='+ this.data.title
    }
  },
  tips:function(content){
    wx.showModal({
      title: "温馨提示",
      content: content,
      showCancel: false,
      confirmText: "确定"
    })
  },
  goTopper:function(e){
    this.setData({
      scrollTop:0
    })
  },
  // jumpLink(e){
  //   wx.redirectTo({
  //       url: '/page/projects/vip/index'
  //     })
  // },
  goTop:function(  ) {
        var acceleration = 0.1;
        var time = 16;
        console.log("fefe")
        var x1 = 0;
        var y1 = 0;
        var x2 = 0;
        var y2 = 0;
        var x3 = 0;
        var y3 = 0;

        if( document.documentElement ) {
            x1 = document.documentElement.scrollLeft || 0;
            y1 = document.documentElement.scrollTop || 0;
        }
        if( document.body ) {
            x2 = document.body.scrollLeft || 0;
            y2 = document.body.scrollTop || 0;
        }
        var x3 = window.scrollX || 0;
        var y3 = window.scrollY || 0;

        // 滚动条到页面顶部的水平距离
        var x = Math.max( x1, Math.max( x2, x3 ) );
        // 滚动条到页面顶部的垂直距离
        var y = Math.max( y1, Math.max( y2, y3 ) );

        // 滚动距离 = 目前距离 / 速度, 因为距离原来越小, 速度是大于 1 的数, 所以滚动距离会越来越小
        var speed = 1 + acceleration;
        window.scrollTo( Math.floor( x / speed ), Math.floor( y / speed ) );

        // 如果距离不为零, 继续调用迭代本函数
        if( x > 0 || y > 0 ) {
            var invokeFunction = "this.goTop(" + acceleration + ", " + time + ")";
            window.setTimeout( invokeFunction, time );
        }
  },
  gundong:function (e) {
    console.log(e)
    var domE,distance
      //if (!domE) return;
      var _onscroll = window.onscroll,
              _onclick = domE.onclick;
      window.onscroll = this.throttle(function(){
          typeof _onscroll === 'function' && _onscroll.apply(this, arguments);
          this.toggleDomE();
      },100);
      domE.onclick = function(){
          typeof _onclick === 'function' && _onclick.apply(this, arguments);
          document.documentElement.scrollTop = 0;
          document.body.scrollTop = 0;
      };
  },
  toggleDomE: function(){
      domE.style.display = (document.documentElement.scrollTop || document.body.scrollTop) > (distance || 500) ? 'block' : 'none';
  },
  throttle:function (func, wait) {
      var timer = null;
      return function () {
          var self = this, args = arguments;
          if (timer) clearTimeout(timer);
          timer = setTimeout(function () {
              return typeof func === 'function' && func.apply(self, args);
          }, wait);
      }
  },
  formSubmit: function(e) {
    var content = e.detail.value;
    console.log(content)
    if(content.studentName==''){
      return this.tips('用户名不能为空')
    }

    if(content.firstPhone==''||!content.firstPhone.match(/1(\d){10}/)){
      return this.tips('手机号格式不正确')
    }
    var url='https://i.hfjy.com/landingForm/register?adidNo=6b398c1237a770ea&formId=19&studentName='+content.studentName+'&firstPhone='+content.firstPhone

    var that = this;
    wx.request({
            url: url,
            method:'GET',
            data: content,
            header: {'Content-Type': 'application/x-www-form-urlencoded'},
            success: function(res) {
              console.log(res)
              if(res.statusCode==200){
                that.setData({status:false});
                setTimeout(function () {
                        that.setData({status:true});
                        
                    }, 2000);
              }
                //this.data.status=false
                
            }
        });
  }
})
